package com.cz.basetool.ui_work.util.system.application;

import android.app.Application;

import com.cz.basetool.ui_work.manager.CrashHandler;
import com.cz.basetool.ui_work.util.log.AndroidConsoleLogPrinter;
import com.cz.basetool.ui_work.util.log.CZLocalLogPrinter;
import com.cz.basetool.ui_work.util.sp.SPUtil;
import com.cz.basetool.ui_work.util.system.application.bugly_strategy.BuglySceneTags;
import com.cz.basetool.ui_work.util.system.application.bugly_strategy.IBuglySetter;
import com.tencent.bugly.crashreport.CrashReport;

/**
 * Created by XinYi on 2019/3/7.
 */

public abstract class BaseApplication extends Application {
    public static DeviceConfig deviceConfig;
    public static Application application;
    @Override
    public void onCreate() {
        super.onCreate();
        this.application = this;
        SPUtil.attachContext(this);

        BaseApplication.deviceConfig = getDeviceConfig();
        //本地日志初始化
//        CZLocalLogPrinter.getInstance().init(this,null);
        CZLocalLogPrinter.getInstance().init(this,new CZLocalLogPrinter.Config(){
            @Override
            public String getHead() {
                return "";
            }
        });

        AndroidConsoleLogPrinter.setOutPut2LocalFile(false);
        //本地异常统计
        CrashHandler crashHandler= CrashHandler.getInstance();
        crashHandler.init(this);

        //腾讯bugly异常统计
        IBuglySetter buglySetter = getBuglySetter();
        CrashReport.initCrashReport(getApplicationContext(), buglySetter.getBuglyKey(), true);
        buglySetter.init();

        CrashReport.setUserSceneTag(this, BuglySceneTags.APLICATION_START); // 上报后的Crash会显示该标签

    }


    public IBuglySetter getBuglySetter(){
        return new IBuglySetter() {
            @Override
            public String getBuglyKey() {
                return "c3fd3d8e9e";
            }

            @Override
            public void init() {
                CrashReport.putUserData(BaseApplication.this, "area", deviceConfig.areaId + "");
                CrashReport.putUserData(BaseApplication.this, "deviceId", deviceConfig.deviceId);
            }
        };
    }


    public abstract DeviceConfig getDeviceConfig();

}
